#include<bits/stdc++.h>
using namespace std;
namespace IO{
    const int BUF=1<<21;
    char buff[BUF],*p1=buff,*p2=buff;
    #define gc() (p1==p2&&(p2=((p1=buff)+fread(buff,1,BUF,stdin)),p1==p2)?EOF:*p1++)
    template<typename T>inline void read(T &x){
        char ch=gc();x=0;int f=1;
        while(!isdigit(ch)){if(ch=='-')f=-1;ch=gc();}
        while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=gc();
        x*=f;
    }
    char obuf[BUF],*p3=obuf;
    inline void pc(char ch){
        if(p3-obuf<BUF) *p3++=ch;
        else fwrite(obuf,p3-obuf,1,stdout),p3=obuf,*p3++=ch;
    }
    inline void put(const char *s){while(*s) pc(*s),++s;}
    char ch[32],ctop;
    template<typename T>inline void print(T x){
    	if(x<0) x=~x+1,pc('-');
        if(!x) return pc(48);
        while(x) ch[++ctop]=x%10^48,x/=10;
        while(ctop) pc(ch[ctop--]);
    }
    inline void flush(){fwrite(obuf,p3-obuf,1,stdout);p3=obuf;}
}
using namespace IO;
const int N=4e5+5;
int T,cnt;
long long X[N],b[N],idx,a[N],sum[N],ans;
bool vis[N];
inline void sol(int ss){
	priority_queue<long long> hp,dp;
	long long sm=0;
	for(int i=1;i<=cnt;++i) sm+=a[i],hp.push(-a[i]),vis[lower_bound(b+1,b+idx+1,a[i])-b]=1;
	for(int t=ss;t<=T;++t){
		long long x=X[t];
		int k=lower_bound(b+1,b+idx+1,x)-b;
		if(vis[k]^=1) hp.push(-x),sm+=x,++cnt;
		else dp.push(-x),sm-=x,--cnt;
		while(!dp.empty()&&hp.top()==dp.top()) hp.pop(),dp.pop();
		if(cnt>1) print(sm+hp.top()*2),pc('\n');
		else pc('0'),pc('\n');
	}
}
int main(){
	freopen("kte.in","r",stdin);
	freopen("kte.out","w",stdout);
	read(T);
	for(int i=1;i<=T;++i) read(X[i]),b[i]=X[i];
	sort(b+1,b+T+1);
	idx=unique(b+1,b+T+1)-b-1;
	const double st=clock();
	for(int t=1;t<=T;++t){
		long long x=X[t];
		if((clock()-st)/CLOCKS_PER_SEC>1.3){sol(t);break;}
		int k=lower_bound(a+1,a+cnt+1,x)-a;
		if(k<=cnt&&a[k]==x){
			--cnt;
			for(int i=k;i<=cnt;++i) sum[i]=sum[i-1]+(a[i]=a[i+1]);
		}else{
			for(int i=++cnt;i>=k;--i){
				a[i]=a[i-1];
				sum[i]=sum[i-1]+x;
			}
			a[k]=x,sum[k]=sum[k-1]+x;
		}
		ans=0;
		long long pr=0;
		for(int i=1;i<cnt;++i){
			ans+=sum[cnt]-sum[cnt-i]-max(sum[i],pr);
			pr=sum[cnt]-sum[cnt-i];
		}
		print(ans),pc('\n');
	}
	flush();
	return 0;
}


